import { request, config } from '../utils'
import * as commonService from './common'

const {api: {orderChangeApply}} = config

/**
 *
 * @param params
 * @returns {Promise<*>}
 */
export async function query (params = {}) {
  params.apiBaseUrl = `${orderChangeApply}`
  return commonService.commonQuery(params)
}

export async function deny (id, params = {}) {
  const url = `${orderChangeApply}/${id}/deny`
  return request({url: url, method: 'POST', data: params})
}

export async function accept (id, version, params = {}) {
  const url = `${orderChangeApply}/${id}/accept/${version}`
  return request({url: url, method: 'POST', data: params})
}

export async function submit (id, version, params = {}) {
  const url = `${orderChangeApply}/${id}/submit/${version}`
  return request({url: url, method: 'PUT', data: params})
}

export async function getChangeDetail (id) {
  const url = `${orderChangeApply}/${id}/detail`
  return request({url: url, method: 'GET'})
}

export async function store (params) {
  const url = `${orderChangeApply}/draft`
  return request({url: url, method: 'POST', data: params})
}

export async function update (params) {
  const url = `${orderChangeApply}/${params.id}/update/${params.version}`
  return request({url: url, method: 'PUT', data: params.values})
}
export async function cancel (id) {
  const url = `${orderChangeApply}/${id}/cancel`
  return request({url: url, method: 'DELETE'})
}
